// 新建util.js
import Web3 from "web3";
import ballotJson from './contract/ballot.json'

const ballotAddr = "0x04BD6FCcA8ABcFADAF3E5D0770f87a1BB968333a";

const useWeb3 = () => {
    const web3 = new Web3("ws://localhost:8545");
    // 新建合约的json文件，并从remix中复制粘贴
    const ballotSm = new web3.eth.Contract(ballotJson.abi, ballotAddr);

    const getAccount = async () => {
        const accounts = await web3.eth.requestAccounts();
        return accounts;
    }

    return {
        web3,
        ballotSm,
        ballotAddr,
        getAccount
    }
};

export default useWeb3;